//
//  CustomTableViewCell.m
//  UI- 电影
//
//  Created by dllo on 16/6/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#define Kwidth self.contentView.frame.size.width
#define Kheight self.contentView.frame.size.height
#import "CustomTableViewCell.h"

@interface CustomTableViewCell ()
@property (nonatomic,retain)UIImageView *movieImageView;
@property (nonatomic,retain)UILabel *nameLabel;
@property (nonatomic,retain)UILabel *idLabel;

@end

@implementation CustomTableViewCell
- (void)dealloc{
    [_movieImageView release];
    [_nameLabel release];
    [_idLabel release];
    [super dealloc];
}
//重写自己的初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //只对属性进行创建
        self.movieImageView = [[UIImageView alloc] init];
        self.nameLabel = [[UILabel alloc] init];
        self.idLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:_movieImageView];
        [self.contentView addSubview:_nameLabel];
        [self.contentView addSubview:_idLabel];
        
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.movieImageView.frame = CGRectMake(10, 10, Kwidth * 0.3, Kheight - 20);
    self.movieImageView.backgroundColor = [UIColor orangeColor];
    //nameLabel
    self.nameLabel.frame = CGRectMake(self.movieImageView.frame.size.width + 40, 20, Kwidth * 0.5, Kheight * 0.2);
    self.nameLabel.backgroundColor = [UIColor greenColor];
    
    self.idLabel.frame = CGRectMake(_nameLabel.frame.origin.x, Kheight * 0.2 + 40, Kwidth * 0.5, Kheight * 0.2);
    self.idLabel.backgroundColor = [UIColor blueColor];
    
}
- (void)setModel:(Modle *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    NSURL *url = [NSURL URLWithString:model.pic_url];
    NSData *data = [NSData dataWithContentsOfURL:url];
    self.movieImageView.image = [UIImage imageWithData:data];
    self.nameLabel.text = model.movieName;
    self.idLabel.text = model.movieId;
}



@end
